package com.jcgyl.export.service.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jcgyl.export.dao.TbInventoryBodyDao;
import com.jcgyl.export.dao.TbInventoryHeadDao;
import com.jcgyl.export.dao.TbreceiptDao;
import com.jcgyl.export.entity.TbInventoryBody;
import com.jcgyl.export.entity.TbInventoryHead;
import com.jcgyl.export.entity.Tbreceipt;
import com.jcgyl.export.mapper.TbInventoryHeadMapper;
import com.jcgyl.export.service.InventoryService;
import com.jcgyl.export.util.entity.JsonUtil;

@Service
public class InventoryServiceImpl implements InventoryService {

	@Autowired
	private TbInventoryHeadDao tbInventoryHeadDao;
	@Autowired
	private TbInventoryBodyDao tbInventoryBodyDao;
	@Autowired
	private TbreceiptDao tbreceiptDao;
	@Autowired
	private TbInventoryHeadMapper tbInventoryHeadMapper;


	@Override
	public void batchInsertInventoryHeads(List<TbInventoryHead> heads) {
		// TODO Auto-generated method stub
		tbInventoryHeadDao.batchInsert(heads);
	}

	@Override
	public void batchInsertInventoryBodies(List<TbInventoryBody> bodies) {
		tbInventoryBodyDao.batchInsert(bodies);
	}

	@Override
	public List<TbInventoryHead> findInventory(String orderNo, String batchNumber, String transferNumber, String Starttime,String Endtime,
			Integer pageSize, Integer pageCount) {
		int startIndex = (pageCount - 1) * pageSize;
		List<TbInventoryHead>list =tbInventoryHeadDao.findInventory(orderNo, batchNumber, transferNumber, Starttime,Endtime,
				startIndex, pageSize);
		return list;
		
	}
	/*
	 * (non-Javadoc)
	 * @see com.jcgyl.export.service.InventoryService#getRowCount(java.lang.String, java.lang.String, 
	 * java.lang.String, java.lang.String, java.lang.String)
	 * 根据条件查询条数
	 * JL
	 */
	@Override
	public int getRowCount(String orderNo, String batchNumber, String transferNumber, String Starttime,String Endtime) {
		int row = tbInventoryHeadDao.getRowCount(orderNo, batchNumber, transferNumber, Starttime, Endtime);
		return row;
	}
	/*
	 * (non-Javadoc)
	 * @see com.jcgyl.export.service.InventoryService#findReceipt(java.lang.String, java.lang.String)
	 * 查询清点回执
	 * JL
	 */
	@Override
	public List<Tbreceipt> findReceipt(String receipttype, String expressnumber) {
		return tbreceiptDao.findObject(receipttype, expressnumber);
	}
	/*
	 * (non-Javadoc)
	 * @see com.jcgyl.export.service.InventoryService#updateByPrimaryKeySelective(com.jcgyl.export.entity.TbInventoryHead)
	 * 修改清单信息
	 * JL
	 */
	@Override
	public int updateByPrimaryKeySelective(TbInventoryHead tbInventoryHead) {
		int row = tbInventoryHeadDao.updateInventory(tbInventoryHead);
		if(row !=1)
			 JsonUtil.error(1, "修改信息失败！");
		return row;
	}
	
}
